home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / dvips / RCS / download.c,v < prev    next >
Encoding:
Text File  |  1990-03-02  |  5.1 KB  |  237 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     90.03.01.23.22.51;  author shirriff;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     90.03.01.23.11.55;  author shirriff;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @Made changes because we seem to name fonts differently.
  27. These changes are necessary for resident fonts to work right.
  28. @
  29. text
  30. @/*
  31.  *   Code to download a font definition at the beginning of a section.
  32.  */
  33. #include "structures.h" /* The copyright notice in that file is included too! */
  34. #ifdef SYSV
  35. #include <string.h>
  36. #else
  37. #include <strings.h>
  38. #endif
  39. /*
  40.  *   These are the external routines we call.
  41.  */
  42. extern int free() ;
  43. extern void numout() ;
  44. extern void mhexout() ;
  45. extern void cmdout() ;
  46. extern long unpack() ;
  47. extern void flip() ;
  48. extern void specialout() ;
  49. extern long getlong() ;
  50. extern void error() ;
  51. extern char *nextstring ;
  52. /*
  53.  *   These are the external variables we access.
  54.  */
  55. extern FILE *bitfile ;
  56. extern fontdesctype *curfnt ;
  57. extern long bytesleft ;
  58. extern quarterword *raster ;
  59. extern Boolean compressed ;
  60. extern integer mag ;
  61. /*
  62.  *   We might use malloc here.
  63.  */
  64. extern char *malloc() ;
  65. /*
  66.  *   We have a routine that downloads an individual character.
  67.  */
  68. void downchar(c, cc)
  69. chardesctype *c ;
  70. shalfword cc ;
  71. {
  72.    register long i, j ;
  73.    register halfword cheight, cwidth ;
  74.    register long k ;
  75.    register quarterword *p ;
  76.    register halfword cmd ;
  77.    register shalfword xoff, yoff ;
  78.    halfword wwidth ;
  79.    register long len ;
  80.  
  81.    p = c->packptr ;
  82.    cmd = *p++ ;
  83.    if (cmd & 4) {
  84.       if ((cmd & 7) == 7) {
  85.          cwidth = getlong(p) ;
  86.          cheight = getlong(p + 4) ;
  87.          xoff = getlong(p + 8) ;
  88.          yoff = getlong(p + 12) ;
  89.          p += 16 ;
  90.       } else {
  91.          cwidth = p[0] * 256 + p[1] ;
  92.          cheight = p[2] * 256 + p[3] ;
  93.          xoff = p[4] * 256 + p[5] ; /* N.B.: xoff, yoff are signed halfwords */
  94.          yoff = p[6] * 256 + p[7] ;
  95.          p += 8 ;
  96.       }
  97.    } else {
  98.       cwidth = *p++ ;
  99.       cheight = *p++ ;
  100.       xoff = *p++ ;
  101.       yoff = *p++ ;
  102.       if (xoff > 127)
  103.          xoff -= 256 ;
  104.       if (yoff > 127)
  105.          yoff -= 256 ;
  106.    }
  107.    if (compressed) {
  108.       len = getlong(p) ;
  109.       p += 4 ;
  110.    } else {
  111.       wwidth = (cwidth + 15) / 16 ;
  112.       i = 2 * cheight * (long)wwidth ;
  113.       if (i <= 0)
  114.          i = 2 ;
  115.       if (bytesleft < i) {
  116.          if (bytesleft >= RASTERCHUNK)
  117.             (void) free((char *) raster) ;
  118.          if (RASTERCHUNK > i) {
  119.             raster = (quarterword *)malloc(RASTERCHUNK) ;
  120.             bytesleft = RASTERCHUNK ;
  121.          } else {
  122.             raster = (quarterword *)malloc((unsigned)i) ;
  123.             bytesleft = i ;
  124.          }
  125.          if (raster == NULL) {
  126.             error("! out of memory during allocation") ;
  127.          }
  128.       }
  129.       k = i;
  130.       while (k > 0)
  131.          raster[--k] = 0 ;
  132.       unpack(p, raster, cwidth, cheight, cmd) ;
  133.       len = i ;
  134.    }
  135.    if (cheight == 0 || cwidth == 0 || len == 0) {
  136.       cwidth = 1 ;
  137.       cheight = 1 ;
  138.       len = 1 ;
  139.       raster[0] = 0 ;
  140.    }
  141. /*
  142.  *   Now we actually send out the data.
  143.  */
  144.    specialout('[') ;
  145.    specialout('<') ;
  146.    if (compressed)
  147.       mhexout(p, len) ;
  148.    else {
  149.       p = raster ;
  150.       i = (cwidth + 7) / 8 ;
  151.       for (j=0; j<cheight; j++) {
  152.          mhexout(p, i) ;
  153.          p += 2*wwidth ;
  154.       }
  155.    }
  156.    specialout('>') ;
  157.    numout((integer)cwidth) ;
  158.    numout((integer)cheight) ;
  159.    numout((integer)(- xoff)) ;
  160.    numout((integer)(cheight - yoff - 1)) ;
  161.    numout((integer)(c->pixelwidth)) ;
  162.    specialout(']') ;
  163.    numout((integer)cc) ;
  164.    cmdout("dc") ;
  165. }
  166. /*
  167.  *   And the download procedure.
  168.  */
  169. void download(p, psfont)
  170. charusetype *p ;
  171. int psfont ;
  172. {
  173.    register halfword b, bit ;
  174.    register chardesctype *c ;
  175.    int cc ;
  176.    char name[10] ;
  177.  
  178.    if (psfont < 27)
  179.       (void)sprintf(name, "/f%c", 'a'+psfont-1) ;
  180.    else
  181.       (void)sprintf(name, "/f%d", psfont-27) ;
  182.    cmdout(name) ;
  183.    curfnt = p->fd ;
  184.    curfnt->psname = psfont ;
  185.    if (curfnt->resfont) {
  186.       cmdout("[") ;
  187.       c = curfnt->chardesc ;
  188.       for (cc=0; cc<256; cc++, c++)
  189.          numout((integer)c->pixelwidth) ;
  190.       cmdout("]") ;
  191.       if (curfnt->resfont->specialinstructions) {
  192.             cmdout(curfnt->resfont->specialinstructions) ;
  193.       } else {
  194.       (void)strcpy(nextstring, "/") ;
  195.       (void)strcat(nextstring, curfnt->resfont->PSname) ;
  196.       cmdout(nextstring) ;
  197.       }
  198.       (void)sprintf(nextstring, "%ld", mag) ;
  199.       cmdout(nextstring) ;
  200.       (void)sprintf(nextstring, "%ld", curfnt->scaledsize) ;
  201.       cmdout(nextstring) ;
  202.       cmdout("rf") ;
  203.       return ;
  204.    }
  205.    cmdout("df") ;
  206.    c = curfnt->chardesc ;
  207.    cc = 0 ;
  208.    for (b=0; b<16; b++) {
  209.       for (bit=32768; bit>0; bit>>=1) {
  210.          if (p->bitmap[b] & bit) {
  211.             downchar(c, cc) ;
  212.             c->flags |= EXISTS ;
  213.          } else
  214.             c->flags &= ~EXISTS ;
  215.          c++ ;
  216.          cc++ ;
  217.       }
  218.    }
  219.    cmdout("dfe") ;
  220. }
  221. @
  222.  
  223.  
  224. 1.1
  225. log
  226. @Initial revision
  227. @
  228. text
  229. @d162 1
  230. a162 4
  231.       (void)strcpy(nextstring, "/") ;
  232.       (void)strcat(nextstring, curfnt->resfont->PSname) ;
  233.       cmdout(nextstring) ;
  234.       if (curfnt->resfont->specialinstructions)
  235. d164 5
  236. @
  237.